<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>Ionic3与Ionic4变更对比 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="Ionic,Angular,">
  

  <meta name="description" content="一、项目差异 不ionic了，以后都angular了。命名方式都用angular的了；provider也改成angular的叫法了，以后请叫service   首先，我们还是以传统的angular来使用之  ionic start &amp;lt;name&amp;gt; &amp;lt;template&amp;gt; [options] ionic start myAppionic start myApp blankioni">
<meta name="keywords" content="Ionic,Angular">
<meta property="og:type" content="article">
<meta property="og:title" content="Ionic3与Ionic4变更对比">
<meta property="og:url" content="http://blog.poetries.top/2019/06/08/ionic3-to-ionic4/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、项目差异 不ionic了，以后都angular了。命名方式都用angular的了；provider也改成angular的叫法了，以后请叫service   首先，我们还是以传统的angular来使用之  ionic start &amp;lt;name&amp;gt; &amp;lt;template&amp;gt; [options] ionic start myAppionic start myApp blankioni">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/7275341-0f971c79cf8f7013.png">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/6197976-e501ab37265544f6.png">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/6197976-9aeda32321efb616.png">
<meta property="og:updated_time" content="2020-08-15T04:25:31.922Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Ionic3与Ionic4变更对比">
<meta name="twitter:description" content="一、项目差异 不ionic了，以后都angular了。命名方式都用angular的了；provider也改成angular的叫法了，以后请叫service   首先，我们还是以传统的angular来使用之  ionic start &amp;lt;name&amp;gt; &amp;lt;template&amp;gt; [options] ionic start myAppionic start myApp blankioni">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/7275341-0f971c79cf8f7013.png">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、项目差异"><span class="toc-text">一、项目差异</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、配置和代理"><span class="toc-text">二、配置和代理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、依赖变更"><span class="toc-text">三、依赖变更</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、css"><span class="toc-text">四、css</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、路由差异"><span class="toc-text">五、路由差异</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#六、生命周期"><span class="toc-text">六、生命周期</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#七、懒加载"><span class="toc-text">七、懒加载</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#八、组件和指令的变更"><span class="toc-text">八、组件和指令的变更</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#九、主题样式的变更"><span class="toc-text">九、主题样式的变更</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-ionic3-to-ionic4" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">Ionic3与Ionic4变更对比</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2019.06.08</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.3k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 5分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、项目差异"><a href="#一、项目差异" class="headerlink" title="一、项目差异"></a>一、项目差异</h2><blockquote>
<p>不<code>ionic</code>了，以后都<code>angular</code>了。命名方式都用<code>angular</code>的了；<code>provider</code>也改成<code>angular</code>的叫法了，以后请叫<code>service</code></p>
</blockquote>
<blockquote>
<p>首先，我们还是以传统的<code>angular</code>来使用之</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ionic start &lt;name&gt; &lt;template&gt; [options]</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ionic start myApp</span><br><span class="line">ionic start myApp blank</span><br><span class="line">ionic start myApp tabs --cordova</span><br><span class="line">ionic start myApp tabs --capacitor</span><br><span class="line">ionic start myApp tabs --<span class="built_in">type</span>=angular</span><br><span class="line">ionic start myApp blank --<span class="built_in">type</span>=ionic1</span><br></pre></td></tr></table></figure>
<blockquote>
<p>其中，创建使用原生功能的项目，除了<code>Cordova</code>外，多了<code>Capacitor</code>的选择，此外，创建<code>Angular</code>版本<code>ionic4</code>项目的命令是这个(注意：带参数。不带参数创建的是<code>ionic3</code>项目)</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ionic start myApp tabs --type=angular</span><br></pre></td></tr></table></figure>
<blockquote>
<p>当然也可以用<code>angular-cli</code>创建普通<code>Angular</code>项目，然后<code>npm</code>添加<code>@ionic/core</code>模块，创建完成后到目录结构如下图所示，它不再像<code>ionic3</code>那样封装了<code>angular</code>项目，而是直接就是一个<code>angular</code>项目，而且默认懒加载</p>
</blockquote>
<p><img src="https://upload-images.jianshu.io/upload_images/7275341-0f971c79cf8f7013.png" alt></p>
<p><img src="https://upload-images.jianshu.io/upload_images/6197976-e501ab37265544f6.png" alt></p>
<h2 id="二、配置和代理"><a href="#二、配置和代理" class="headerlink" title="二、配置和代理"></a>二、配置和代理</h2><blockquote>
<p><code>v4</code>同<code>angular</code>配置保持一致，可以在<code>angular.json</code>中进行一系列配置，代理则通过<code>proxy.config.json</code>配置</p>
</blockquote>
<h2 id="三、依赖变更"><a href="#三、依赖变更" class="headerlink" title="三、依赖变更"></a>三、依赖变更</h2><ul>
<li><code>ionic-angular</code> 引入变为了<code>@ionic/angular</code></li>
<li><code>rxjs</code>变化主要是由于<code>rxjs5.5</code>引入了<code>Pipeable Operator</code>，<a href="https://zhuanlan.zhihu.com/p/36106514" target="_blank" rel="noopener">参考这里rxjs</a></li>
</ul>
<h2 id="四、css"><a href="#四、css" class="headerlink" title="四、css"></a>四、css</h2><ul>
<li>和<code>angular</code>保持一致，采用<code>style</code>或<code>styleUrls</code>方式引入，不再使用<code>page-**{}</code>方式</li>
<li>全局样式：可以将<code>v3</code>中全局样式放置到<code>global.scss</code>中，也可以创建一个新的<code>scss</code>引入到<code>angular.json</code>中</li>
</ul>
<p><img src="https://upload-images.jianshu.io/upload_images/6197976-9aeda32321efb616.png" alt></p>
<h2 id="五、路由差异"><a href="#五、路由差异" class="headerlink" title="五、路由差异"></a>五、路由差异</h2><blockquote>
<p><code>angular</code> 路由官方文档 <a href="https://angular.cn/guide/router" target="_blank" rel="noopener">https://angular.cn/guide/router</a></p>
</blockquote>
<blockquote>
<p>也许<code>Ionic 4</code>中最显着的变化，以及需要对现有应用程序进行最大改变的变化，是转向<code>Angular</code>风格的路由。<code>Ionic</code>过去使用的典型<code>Push/Pop</code>风格导航仍然可用，您甚至可以直接通过<code>Ionic</code>的<code>Web</code>组件使用这种导航方式，但推荐的方法是使用<code>Angular Router</code></p>
</blockquote>
<p>观察目录结构，很容易发现这是一个<code>angular</code>项目，是因为它有一个<code>routing</code>模块</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; NgModule &#125; <span class="keyword">from</span> <span class="string">'@angular/core'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; Routes, RouterModule &#125; <span class="keyword">from</span> <span class="string">'@angular/router'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> routes: Routes = [</span><br><span class="line">  &#123; <span class="attr">path</span>: <span class="string">''</span>, <span class="attr">loadChildren</span>: <span class="string">'./tabs/tabs.module#TabsPageModule'</span> &#125;</span><br><span class="line">];</span><br><span class="line">@NgModule(&#123;</span><br><span class="line">  imports: [RouterModule.forRoot(routes)],</span><br><span class="line">  exports: [RouterModule]</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">AppRoutingModule</span> </span>&#123;&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>而对应的路由组件是<code>ion-router-outlet</code>，是对<code>Angular</code>的<code>router-outlet</code>扩展，以兼容旧的导航方式，打开<code>tabs.page.html</code>可看到下面内容</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ion-tabs</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">ion-tab</span> <span class="attr">label</span>=<span class="string">"Home"</span> <span class="attr">icon</span>=<span class="string">"home"</span> <span class="attr">href</span>=<span class="string">"/tabs/(home:home)"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ion-router-outlet</span> <span class="attr">name</span>=<span class="string">"home"</span>&gt;</span><span class="tag">&lt;/<span class="name">ion-router-outlet</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">ion-tab</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">ion-tab</span> <span class="attr">label</span>=<span class="string">"About"</span> <span class="attr">icon</span>=<span class="string">"information-circle"</span> <span class="attr">href</span>=<span class="string">"/tabs/(about:about)"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ion-router-outlet</span> <span class="attr">name</span>=<span class="string">"about"</span>&gt;</span><span class="tag">&lt;/<span class="name">ion-router-outlet</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">ion-tab</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">ion-tab</span> <span class="attr">label</span>=<span class="string">"Contact"</span> <span class="attr">icon</span>=<span class="string">"contacts"</span> <span class="attr">href</span>=<span class="string">"/tabs/(contact:contact)"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ion-router-outlet</span> <span class="attr">name</span>=<span class="string">"contact"</span>&gt;</span><span class="tag">&lt;/<span class="name">ion-router-outlet</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">ion-tab</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ion-tabs</span>&gt;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>而原来<code>ionic3</code>的生命周期函数由原来的</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ionViewDidLoad</span><br><span class="line">ionViewWillEnter</span><br><span class="line">ionViewDidEnter</span><br><span class="line">ionViewWillLeave</span><br><span class="line">ionViewDidLeave</span><br><span class="line">ionViewWillUnload</span><br><span class="line">ionViewCanEnter</span><br><span class="line">ionViewCanLeave</span><br></pre></td></tr></table></figure>
<p>也相应做了调整，如</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ionNavDidChange</span><br><span class="line">ionNavWillChange</span><br><span class="line">ionNavWillLoad</span><br></pre></td></tr></table></figure>
<blockquote>
<p>言外之意是，你既可以使用如下<code>Angular</code>方式做路由跳转</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">this.router.navigateByUrl(&apos;/login&apos;);</span><br><span class="line">this.router.navigate([&apos;/detail&apos;, &#123; id: itemId &#125;]);</span><br></pre></td></tr></table></figure>
<blockquote>
<p>也可以使用原有<code>Ionic</code>方式管控堆栈：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">this</span>.navCtrl.goForward(<span class="string">'/route'</span>);</span><br><span class="line"><span class="keyword">this</span>.navCtrl.goBack(<span class="string">'/route'</span>);</span><br><span class="line"><span class="keyword">this</span>.navCtrl.goRoot(<span class="string">'/route'</span>);</span><br></pre></td></tr></table></figure>
<blockquote>
<p>前者注重<code>URL</code>管控，好处是灵活控制跳转的位置；后者注重代码管控，好处是它允许您指定导航的“方向”，这将有助于<code>Ionic &lt;ion-router-outlet&gt;</code>正确显示页面过渡。</p>
</blockquote>
<h2 id="六、生命周期"><a href="#六、生命周期" class="headerlink" title="六、生命周期"></a>六、生命周期</h2><blockquote>
<p>一些 <code>Ionic</code> 生命周期事件等同于 <code>Angular</code> 生命周期 <code>hooks</code>。 例如，<code>ionViewDidLoad()</code> 扮演与 <code>Angular OnInit</code>生命周期 <code>hook（ngOnInit()</code>）相同的角色。 在这种情况下，请使用 <code>Angular</code> 生命周期 <code>hooks</code></p>
</blockquote>
<h2 id="七、懒加载"><a href="#七、懒加载" class="headerlink" title="七、懒加载"></a>七、懒加载</h2><blockquote>
<p>推荐使用<code>angular</code>路由的<code>loadChildren</code>方法实现</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// v3 home.page.ts</span></span><br><span class="line">@IonicPage(&#123;</span><br><span class="line">  segment: <span class="string">'home'</span></span><br><span class="line">&#125;)</span><br><span class="line">@Component(&#123; ... &#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">HomePage</span> </span>&#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// home.module.ts</span></span><br><span class="line">@NgModule(&#123;</span><br><span class="line">  declarations: [HomePage],</span><br><span class="line">  imports: [IonicPageModule.forChild(HomePage)]</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">HomePageModule</span> </span>&#123;&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// v4 home.module.ts</span></span><br><span class="line">@NgModule(&#123;</span><br><span class="line">  imports: [</span><br><span class="line">    IonicModule,</span><br><span class="line">    RouterModule.forChild([&#123; <span class="attr">path</span>: <span class="string">''</span>, <span class="attr">component</span>: HomePage &#125;])</span><br><span class="line">  ],</span><br><span class="line">  declarations: [HomePage]</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">HomePageModule</span> </span>&#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// app.module.ts</span></span><br><span class="line">@NgModule(&#123;</span><br><span class="line">  declarations: [AppComponent],</span><br><span class="line">  imports: [</span><br><span class="line">    BrowserModule,</span><br><span class="line">    IonicModule.forRoot(),</span><br><span class="line">    RouterModule.forRoot([</span><br><span class="line">      &#123; <span class="attr">path</span>: <span class="string">'home'</span>, <span class="attr">loadChildren</span>: <span class="string">'./pages/home/home.module#HomePageModule'</span> &#125;,</span><br><span class="line">      &#123; <span class="attr">path</span>: <span class="string">''</span>, <span class="attr">redirectTo</span>: <span class="string">'home'</span>, <span class="attr">pathMatch</span>: <span class="string">'full'</span> &#125;</span><br><span class="line">    ])</span><br><span class="line">  ],</span><br><span class="line">  bootstrap: [AppComponent]</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">AppModule</span> </span>&#123;&#125;</span><br></pre></td></tr></table></figure>
<h2 id="八、组件和指令的变更"><a href="#八、组件和指令的变更" class="headerlink" title="八、组件和指令的变更"></a>八、组件和指令的变更</h2><blockquote>
<p><code>Ionic</code>为了更通用化，把原来的指令调整为更通用标准的属性方式，如<code>icon-right</code>调整为<code>slot=&quot;end&quot;</code>, <code>large</code>变成<code>size=&quot;large&quot;</code>,<code>&lt;button ion-button&gt;</code>变为<code>&lt;ion-button&gt;</code>，所以对于<code>ionic4</code>的组件使用，还是建议先上官网了解组件的api，特别留意下<code>xxx-controller</code>的变更，常见的有如下几个</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">modal-controller</span><br><span class="line">popover-controller</span><br><span class="line">action-sheet-controller</span><br><span class="line">loading-controller</span><br><span class="line">……</span><br></pre></td></tr></table></figure>
<blockquote>
<p>前面2个一般是有自定义UI的，在<code>ionic3</code>中是可通过自定义组件注入<code>ViewController</code>来关闭窗口，在<code>ionic4</code>中已经没有这个方法，改为通过监听事件或回调给外面的<code>xxx-controller</code>来关闭</p>
</blockquote>
<blockquote>
<p>注意：也就是说现有的一些第三方<code>ionic2/3</code>组件大部分不能用在<code>ionic4</code>上，但是<code>angular2+</code>的组件就可以</p>
</blockquote>
<p><strong>组件变更</strong></p>
<blockquote>
<p><code>Loading</code>，<code>Toast</code> 或 <code>Alert</code> 等组件在<code>v3</code>是同步创建的。 在 <code>Ionic v4</code> 中，这些组件都是基于 <code>promise</code>异步创建的</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// v3</span></span><br><span class="line">showAlert() &#123;</span><br><span class="line">  <span class="keyword">const</span> alert = <span class="keyword">this</span>.alertCtrl.create(&#123;</span><br><span class="line">    message: <span class="string">"Hello There"</span>,</span><br><span class="line">    subHeader: <span class="string">"I'm a subheader"</span></span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">  alert.present();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// v4</span></span><br><span class="line">showAlert() &#123;</span><br><span class="line">  <span class="keyword">this</span>.alertCtrl.create(&#123;</span><br><span class="line">    message: <span class="string">"Hello There"</span>,</span><br><span class="line">    subHeader: <span class="string">"I'm a subheader"</span></span><br><span class="line">  &#125;).then(<span class="function"><span class="params">alert</span> =&gt;</span> alert.present());</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Or using async/await</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> showAlert() &#123;</span><br><span class="line">  <span class="keyword">const</span> alert = <span class="keyword">await</span> <span class="keyword">this</span>.alertCtrl.create(&#123;</span><br><span class="line">    message: <span class="string">"Hello There"</span>,</span><br><span class="line">    subHeader: <span class="string">"I'm a subheader"</span></span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">  <span class="keyword">await</span> alert.present();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="九、主题样式的变更"><a href="#九、主题样式的变更" class="headerlink" title="九、主题样式的变更"></a>九、主题样式的变更</h2><blockquote>
<p>这一块也是变更比较大的，主要是<code>ionic4</code>使用了大量的<code>ShadowDOM</code>和<code>CSS</code>变量</p>
</blockquote>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2019/06/08/taro-summary/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2019/08/10/react-good-practice/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
